package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/7/30 22:50
 * @description：https://leetcode-cn.com/problems/excel-sheet-column-number/
 */
public class Excel表列序号 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.titleToNumber("FXSHRXW"));

    }

    class Solution {
        public int titleToNumber(String columnTitle) {
            char[] chars = columnTitle.toCharArray();
            int len = chars.length;
            int sum = 0;
            int factor = 1;
            for (int i = len - 1; i >= 0; i--) {
                int cur = chars[i] - 'A' + 1;
                sum += cur * factor;
                factor *= 26;
            }
            return sum;
        }
    }
}
